<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2018/4/17
  Time: 16:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String username = request.getParameter("username");
    String password = request.getParameter("password");


    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;

    String sql = "SELECT username,password from t_users where username = '" + username + "'and password = '" + password + "'";

    Class.forName("com.mysql.jdbc.Driver");

    connection = DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone = UTC",
            "root",
            "123456"
    );

    statement = connection.createStatement();
    resultSet = statement.executeQuery(sql);

    if (resultSet.next()) {
        session.setAttribute("isLogin", "ture");
        response.sendRedirect("userList.jsp");
    } else {
        out.write("<p>登录信息有误</p>");
    }
    resultSet.close();
    statement.close();
    connection.close();

//    if ("admin".equals(username) &&
//            "123456".equals(password)){
//        // 管理员可以登录
//        out.write("登录成功！");
//
//        session.setAttribute("isLogin", "true");
//
//        response.sendRedirect("index.jsp");
//
//    }else{
//
//        out.write("<p>用户名或密码错误。</p>");
//    }
%>
<jsp:include page="footer.jsp">
    <jsp:param name="year" value="2018"/>
</jsp:include>
</body>
</html>
